using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class JobSeekers_coverletter : System.Web.UI.Page
{
    string connectionString = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        connectionString =
             WebConfigurationManager.ConnectionStrings[
               "Database2000"].ConnectionString;
        if (Session.Contents["jsuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else
        {
            string letterID = Request.QueryString.Get("LetterID");
            if (!IsPostBack)
                EditCoverLetter(letterID);
        }
    }
    void EditCoverLetter(string letterID)
    {
        if (letterID != "" && letterID !=null )
        {
            SqlServerProvider cls = new SqlServerProvider(connectionString);
            cls.CommandText = "select * from tblJSCoverLetters " +
            " where UserID='" + Session["jsuserid"] +
             "' and LetterID='" + letterID  
             + "'";
            DataTable dataTable =
            cls.GetDataTable( );
            LetterID.Value = dataTable.Rows[0][0].ToString();       
            txtSubject.Text = dataTable.Rows[0][2].ToString();            
            txtBody.Text = dataTable.Rows[0][3].ToString();            
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string id = "0";
        if (LetterID.Value != "")
            id = LetterID.Value;

        SqlServerProvider cls = new SqlServerProvider(connectionString);
        if (!cls.AddNewUpdateCoverLetter(id,
        Convert.ToString(Session.Contents["jsuserid"]),
        txtSubject.Text,txtBody.Text))
            literalError.Text = "Error: " + cls.ErrorMessage;
        else
            Response.Redirect("coverletters.aspx");           
    }
}
